package com.hengtiansoft.lfy.widget;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.hengtiansoft.lfy.R;

/**
 * 自定义toast（解决长期显示问题）
 * daiye
 */
public class MyToast {

    private static Toast mToast;

    public static void show(Context mContext, int resId) {
        show(mContext, mContext.getResources().getString(resId), Toast.LENGTH_SHORT);
    }

    public static void show(Context mContext, int resId, int duration) {
        show(mContext, mContext.getResources().getString(resId), duration);
    }

    public static void show(Context mContext, String msg) {
        show(mContext, msg, Toast.LENGTH_SHORT);
    }

    public static void show(Context context, String msg, int duration) {
//        mHandler.removeCallbacks(r);
        TextView txt = new TextView(context);
        txt.setTextSize(16);
        txt.setLayoutParams(new ViewGroup.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
        txt.setText(msg);

        txt.setTextColor(context.getResources().getColor(android.R.color.white));
        txt.setBackgroundResource(R.drawable.background_standard_gray);
        float paddingLeft = 40;
        float paddingTop = 20;

        txt.setPadding((int) paddingLeft, (int) paddingTop, (int) paddingLeft, (int) paddingTop);
        if (mToast == null) {
            mToast = new Toast(context);
        }

        mToast.setView(txt);
        mToast.setDuration(duration);
//        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.show();

//        mHandler.postDelayed(r, duration);
        mToast.show();
    }
}
